package com.itheima.config;

import com.itheima.interceptor.DemoInterceptor;
import com.itheima.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration//标明当前类是一个配置类
public class WebConfig implements WebMvcConfigurer {

    //从spring中获取拦截器对象
    @Autowired
    private TokenInterceptor tokenInterceptor;

    //注册一个拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //  registry 拦截器的注册器 添加一个拦截器
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login","/upload");//设置了不拦截路径

    }
}
